﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMP.ERP.BLL;
using System.Data;
using System.Data.SqlClient;
using CMP.ERP.Model;

namespace CMP.ERP.Admin.Controllers
{
    public class PurchasetoController : Controller
    {
        WeighBLL bll = new WeighBLL();
        // GET: /Purchase/
        /// <summary>
        /// 称重
        /// </summary>
        /// <returns></returns>
        public ActionResult Purchaseto_Show()
        {

            List<Weigh> list = new List<Weigh>();
            DataTable data = bll.GetShow();
            foreach (DataRow item in data.Rows)
            {
                Weigh w = new Weigh();
                w.Weigh_Id = Convert.ToInt32(item["Weigh_Id"]);
                w.Weigh_danhao = item["Weigh_danhao"].ToString();
                w.Shipments_Per = item["Shipments_Per"].ToString();
                w.Shipments_Phone = item["Shipments_Phone"].ToString();
                w.Weigh_kilogram = item["Weigh_kilogram"].ToString();
                w.Weigh_money = Convert.ToInt32(item["Weigh_money"]);
                list.Add(w);
            }
            return View(list);
        }
        /// <summary>
        /// 添加视图
        /// </summary>
        /// <returns></returns>
        public ActionResult Get_xiala()
        {
            List<Shipments> list = new List<Shipments>();
            DataTable data = bll.Getxiala();
            foreach (DataRow item in data.Rows)
            {
                Shipments s = new Shipments();
                s.Shipments_Id = Convert.ToInt32(item["Shipments_Id"]);
                s.Shipments_Per = item["Shipments_Per"].ToString();
                list.Add(s);
            }
            return Json(list);
        }

        /// <summary>
        /// 添加方法
        /// </summary>
        /// <param name="w"></param>
        /// <returns></returns>
        public ActionResult Getadd(int Shipments_Id, int Weigh_money, string Weigh_kilogram, string Weigh_danhao)
        {
            if (bll.Getadd(Shipments_Id, Weigh_money, Weigh_kilogram, Weigh_danhao) > 0)
            {
                return Content("<script>alert('添加成功');location.href='/Purchaseto/Purchaseto_Show'</script>");
            }
            else
            {
                return Content("<script>alert('添加失败');location.href='/Purchaseto/Purchaseto_Show'</script>");
            }
        }
        [HttpGet]
        /// <summary>
        /// 根据单号查找
        /// </summary>
        /// <param name="danhao"></param>
        /// <returns></returns>
        public ActionResult Getchaxun(string danhao)
        {
            List<Weigh> list = new List<Weigh>();
            DataTable data = bll.Getchaxun(danhao);
            foreach (DataRow item in data.Rows)
            {
                Weigh w = new Weigh();
                w.Weigh_Id = Convert.ToInt32(item["Weigh_Id"]);
                w.Weigh_danhao = item["Weigh_danhao"].ToString();
                w.Shipments_Per = item["Shipments_Per"].ToString();
                w.Shipments_Phone = item["Shipments_Phone"].ToString();
                w.Weigh_kilogram = item["Weigh_kilogram"].ToString();
                w.Weigh_money = Convert.ToInt32(item["Weigh_money"]);
                list.Add(w);
            }
            return View("Purchaseto_Show",list);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        public ActionResult Getdelete(int id)
        {
            if (bll.Getdelete(id) > 0)
            {
                return Content("<script>alert('删除成功');location.href='/Purchaseto/Purchaseto_Show'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');location.href='/Purchaseto/Purchaseto_Show'</script>");
            }
        }
    }
}
